package cn.bs.allensocket.good;

/**
 * Created by Allen on 2014/11/7.
 */
public class GodMain {

    public static void main(String[] args){
        Godown godown = new Godown(30);
        Consumer c1 = new Consumer(50,godown);
        Consumer c2 = new Consumer(30,godown);
        Consumer c3 = new Consumer(80,godown);
        Producer p1 = new Producer(10, godown);
        Producer p2 = new Producer(10, godown);
        Producer p3 = new Producer(10, godown);
        Producer p4 = new Producer(10, godown);
        Producer p5 = new Producer(10, godown);
        Producer p6 = new Producer(10, godown);
        Producer p7 = new Producer(80, godown);

        c1.start();
        c2.start();
        c3.start();
        p1.start();
        p2.start();
        p3.start();
        p4.start();
        p5.start();
        p6.start();
        p7.start();
    }

    //生产者
    static class Producer extends Thread {
        private int neednum;    //生产产品数量
        private Godown godown;  //仓库
        Producer(int neednum,Godown godown){
            this.neednum = neednum;
            this.godown = godown;
        }
        public void run(){
            godown.produce(neednum);
        }
    }
    //消费者
    static class Consumer extends Thread {
        private int neednum;
        private  Godown godown;
        Consumer(int neednum,Godown godown){
            this.neednum = neednum;
            this.godown = godown;
        }
        public void run(){
            godown.consume(neednum);
        }
    }
}
